//
//  DHTabBarRootController.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/4/12.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHTabBarRootController.h"

@interface DHTabBarRootController ()

@end

@implementation DHTabBarRootController

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[SDWebImageManager sharedManager].imageCache clearMemory];
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    if (self.navigationView.leftMenuBGView.hidden || !self.navigationView.leftMenuBGView) {
        self.tabBarController.tabBar.hidden = NO;
    }else{
        self.tabBarController.tabBar.hidden = YES;
    }
    
    // 刷新通知数量
    if ([Login isLogin]) {
        [[GlobalManager shareGlobalManager] refreshNotificationsUnreadCountAndBlock:^(id data, NSError *error) {
            self.navigationView.messageButton.countLabel.text = [NSString stringWithFormat:@"%ld",(long)[GlobalManager shareGlobalManager].notificationsUnreadCount];
            if ([GlobalManager shareGlobalManager].notificationsUnreadCount == 0) {
                self.navigationView.messageButton.countLabel.hidden = YES;
            }else{
                self.navigationView.messageButton.countLabel.hidden = NO;
            }
        }];
    }else{
        self.navigationView.messageButton.countLabel.hidden = YES;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    CGFloat height = 64;
    int navigationTop = 0;
    if (iPhoneX) {
        navigationTop = 20;
        height = 64;
    }
    if (!self.navigationView) {
        self.navigationView = [[DHRootNavigationView alloc] initWithFrame:CGRectMake(0, navigationTop, kScreenWidth, height)];
        self.navigationView.leftMenuBGView.hidden = YES;
        [self.view addSubview:self.navigationView];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    [[SDWebImageManager sharedManager].imageCache clearMemory];
}

@end
